package Java.ReadWriteLock;

//写锁降级

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Demo1 {
    public static void main(String[] args) {
        //可重入锁读写对象
        ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        //读锁
        ReentrantReadWriteLock.ReadLock readLock = readWriteLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = readWriteLock.writeLock();


//        //锁降级:写的时候也能读
//        //1.获取写锁
//        writeLock.lock();
//        System.out.println("abfsfs");
//
//        //2 获取读锁
//        readLock.lock();;
//        System.out.println("---read");
//
//        //释放写锁
//        writeLock.unlock();
//
//
//        //释放读锁
//        readLock.unlock();


        //读锁不能升级为写锁
        readLock.lock();
        ;
        System.out.println("---read");

        writeLock.lock();
        System.out.println("abfsfs");
    }
}
